{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**9. Palindrome Number**  <font color=green size=3>_easy_</font>\n",
    "\n",
    "Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.\n",
    "\n",
    "**Example 1**\n",
    "\n",
    "```\n",
    "Input: 121\n",
    "Output: true\n",
    "```\n",
    "**Example 2**\n",
    "\n",
    "```\n",
    "Input: -121\n",
    "Output: false\n",
    "Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.\n",
    "```\n",
    "**Example 3**\n",
    "\n",
    "```\n",
    "Input: 10\n",
    "Output: false\n",
    "Explanation: Reads 01 from right to left. Therefore it is not a palindrome.\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "def convert(num):\n",
    "    \"\"\"\n",
    "    Input: '42'\n",
    "    Output: 42\n",
    "    \"\"\"\n",
    "    if num < 0:\n",
    "        return False\n",
    "\n",
    "    rev = 0\n",
    "    num_copy = num\n",
    "    while num_copy != 0:\n",
    "        pop = num_copy % 10\n",
    "        num_copy /= 10\n",
    "        rev = rev * 10 + pop\n",
    "    return rev == num\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    print(convert(121))\n",
    "    print(convert(-121))\n",
    "    print(convert(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
